package demo.filter03;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;
import java.io.PrintWriter;

@WebFilter(filterName = "MyFilter03",urlPatterns = "/MyServlet2")
public class MyFiler03 implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 过滤器对象在初始化时调用，可以配置一些初始化参数
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 用于拦截用户的请求，如果和当前过滤器的拦截路径匹配，该方法会被调用
        PrintWriter out = servletResponse.getWriter();
        out.println("MyFilter03 wwwww");
        filterChain.doFilter(servletRequest, servletResponse);
        out.println("MyFilter03 sssss");
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
